
<!DOCTYPE HTML>
<html lang="zh" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Pine 第 3 版迁移指南 · Pine Script 用户手册中文版</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="剑客">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2how.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="輸入並搜尋" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Introduction.html">
            
                <a href="../Introduction.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../quickstart/">
            
                <a href="../quickstart/">
            
                    
                    快速开始
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../quickstart/example.html">
            
                <a href="../quickstart/example.html">
            
                    
                    Pine Script 示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../quickstart/studyVsStrategy.html">
            
                <a href="../quickstart/studyVsStrategy.html">
            
                    
                    “study” 与 “strategy”
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../quickstart/model.html">
            
                <a href="../quickstart/model.html">
            
                    
                    Pine Script 执行模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../quickstart/series.html">
            
                <a href="../quickstart/series.html">
            
                    
                    序列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../quickstart/understanding.html">
            
                <a href="../quickstart/understanding.html">
            
                    
                    理解 Pine Script
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../quickstart/editor.html">
            
                <a href="../quickstart/editor.html">
            
                    
                    Pine 编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../quickstart/next.html">
            
                <a href="../quickstart/next.html">
            
                    
                    下一步
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../fundamentals/">
            
                <a href="../fundamentals/">
            
                    
                    语言基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../fundamentals/1structure.html">
            
                <a href="../fundamentals/1structure.html">
            
                    
                    脚本结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../fundamentals/2version.html">
            
                <a href="../fundamentals/2version.html">
            
                    
                    版本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../fundamentals/3comment.html">
            
                <a href="../fundamentals/3comment.html">
            
                    
                    注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../fundamentals/4identifier.html">
            
                <a href="../fundamentals/4identifier.html">
            
                    
                    标识符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../fundamentals/5line.html">
            
                <a href="../fundamentals/5line.html">
            
                    
                    换行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../fundamentals/6type.html">
            
                <a href="../fundamentals/6type.html">
            
                    
                    类型系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../fundamentals/7operator.html">
            
                <a href="../fundamentals/7operator.html">
            
                    
                    运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../fundamentals/8function.html">
            
                <a href="../fundamentals/8function.html">
            
                    
                    函数和注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../fundamentals/9expressions.html">
            
                <a href="../fundamentals/9expressions.html">
            
                    
                    表达式、声明和语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../fundamentals/10function.html">
            
                <a href="../fundamentals/10function.html">
            
                    
                    函数声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="../fundamentals/11model.html">
            
                <a href="../fundamentals/11model.html">
            
                    
                    执行模型
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../features/">
            
                <a href="../features/">
            
                    
                    基本功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../features/1alert.html">
            
                <a href="../features/1alert.html">
            
                    
                    警报
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../features/2array.html">
            
                <a href="../features/2array.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../features/3barstate.html">
            
                <a href="../features/3barstate.html">
            
                    
                    柱状态，内置变量 barstate.*
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../features/4color.html">
            
                <a href="../features/4color.html">
            
                    
                    颜色
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../features/5context.html">
            
                <a href="../features/5context.html">
            
                    
                    上下文切换和 security 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../features/6drawing.html">
            
                <a href="../features/6drawing.html">
            
                    
                    绘图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../features/7extend.html">
            
                <a href="../features/7extend.html">
            
                    
                    延长和扩展交易数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../features/8reapint.html">
            
                <a href="../features/8reapint.html">
            
                    
                    指标重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../features/9nonstandard.html">
            
                <a href="../features/9nonstandard.html">
            
                    
                    非标准图表类型数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="../features/10session.html">
            
                <a href="../features/10session.html">
            
                    
                    交易时段和时间信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="../features/11strategies.html">
            
                <a href="../features/11strategies.html">
            
                    
                    策略
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="../features/12table.html">
            
                <a href="../features/12table.html">
            
                    
                    图表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../annotations/">
            
                <a href="../annotations/">
            
                    
                    注解概览
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../annotations/1study.html">
            
                <a href="../annotations/1study.html">
            
                    
                    指标注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../annotations/2plot.html">
            
                <a href="../annotations/2plot.html">
            
                    
                    绘图注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../annotations/3input.html">
            
                <a href="../annotations/3input.html">
            
                    
                    脚本输入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../annotations/4price.html">
            
                <a href="../annotations/4price.html">
            
                    
                    价格水平，hline
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../annotations/5fill.html">
            
                <a href="../annotations/5fill.html">
            
                    
                    用 fill 填充背景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../annotations/6barcolor.html">
            
                <a href="../annotations/6barcolor.html">
            
                    
                    使用 barcolor 为 series 着色
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../annotations/7bg.html">
            
                <a href="../annotations/7bg.html">
            
                    
                    使用 bgcolor 进行背景着色
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../annotations/8shape.html">
            
                <a href="../annotations/8shape.html">
            
                    
                    绘制形状、字符和箭头
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../annotations/9custom.html">
            
                <a href="../annotations/9custom.html">
            
                    
                    定制 OHLC 柱和蜡烛
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../debugging/">
            
                <a href="../debugging/">
            
                    
                    调试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../debugging/1introduction.html">
            
                <a href="../debugging/1introduction.html">
            
                    
                    指标注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../debugging/2land.html">
            
                <a href="../debugging/2land.html">
            
                    
                    功能位置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../debugging/3num.html">
            
                <a href="../debugging/3num.html">
            
                    
                    显示数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../debugging/4str.html">
            
                <a href="../debugging/4str.html">
            
                    
                    显示字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../debugging/5conditions.html">
            
                <a href="../debugging/5conditions.html">
            
                    
                    调试条件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../debugging/6fn.html">
            
                <a href="../debugging/6fn.html">
            
                    
                    从内部函数调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../debugging/7for.html">
            
                <a href="../debugging/7for.html">
            
                    
                    从“for”循环内部调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../debugging/8tips.html">
            
                <a href="../debugging/8tips.html">
            
                    
                    提示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../publishing/">
            
                <a href="../publishing/">
            
                    
                    发布脚本
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../publishing/1pvp.html">
            
                <a href="../publishing/1pvp.html">
            
                    
                    公共脚本与私有脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../publishing/2mode.html">
            
                <a href="../publishing/2mode.html">
            
                    
                    发布模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../publishing/3ps.html">
            
                <a href="../publishing/3ps.html">
            
                    
                    如何发布脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../publishing/4us.html">
            
                <a href="../publishing/4us.html">
            
                    
                    如何更新脚本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../library/">
            
                <a href="../library/">
            
                    
                    公共库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../library/1description.html">
            
                <a href="../library/1description.html">
            
                    
                    描述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../library/2copy.html">
            
                <a href="../library/2copy.html">
            
                    
                    将脚本从公共库复制到您的个人库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../library/3editing.html">
            
                <a href="../library/3editing.html">
            
                    
                    编辑来自公共库的脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../library/4searching.html">
            
                <a href="../library/4searching.html">
            
                    
                    搜索脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../library/5video.html">
            
                <a href="../library/5video.html">
            
                    
                    教学视频
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="./">
            
                <a href="./">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.10.1" data-path="1migration.html">
            
                <a href="1migration.html">
            
                    
                    Pine 第 3 版迁移指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="2how.html">
            
                <a href="2how.html">
            
                    
                    操作指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="3err.html">
            
                <a href="3err.html">
            
                    
                    Pine 的编译和执行错误
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../more/">
            
                <a href="../more/">
            
                    
                    我可以从哪里获得更多信息？
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本書使用 GitBook 釋出
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Pine 第 3 版迁移指南</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="pine-&#x7B2C;-3-&#x7248;&#x8FC1;&#x79FB;&#x6307;&#x5357;">Pine &#x7B2C; 3 &#x7248;&#x8FC1;&#x79FB;&#x6307;&#x5357;</h1>
<p>&#x672C;&#x6587;&#x6863;&#x6709;&#x52A9;&#x4E8E;&#x5C06; Pine &#x811A;&#x672C;&#x4EE3;&#x7801;&#x4ECE; @version=2 &#x8FC1;&#x79FB;&#x5230; @version=3&#x3002;</p>
<h2 id="security-&#x51FD;&#x6570;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#x5DF2;&#x7ECF;&#x6539;&#x53D8;">security &#x51FD;&#x6570;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#x5DF2;&#x7ECF;&#x6539;&#x53D8;</h2>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;&#x7B80;&#x5355;&#x7684; security &#x51FD;&#x6570;&#x7528;&#x4F8B;&#x3002;&#x5728;&#x4E00;&#x4E2A;&#x65E5;&#x5185;&#x56FE;&#x4E0A;&#x6DFB;&#x52A0;&#x8FD9;&#x4E2A;&#x6307;&#x6807;&#xFF1A;</p>
<pre><code>// Add this indicator on an intraday (e.g., 30 minutes) chart
//@version=2
study(&quot;My Script&quot;, overlay=true)
s = security(tickerid, &apos;D&apos;, high, false)
plot(s)
</code></pre><p>&#x8FD9;&#x4E2A;&#x6307;&#x6807;&#x662F;&#x6839;&#x636E;&#x5386;&#x53F2;&#x6570;&#x636E;&#x8BA1;&#x7B97;&#x7684;&#xFF0C;&#x5E76;&#x5728;&#x4E00;&#x5B9A;&#x7A0B;&#x5EA6;&#x4E0A;&#x5C55;&#x671B;&#x672A;&#x6765;&#x3002;&#x5728;&#x6BCF;&#x4E2A;&#x65F6;&#x6BB5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x67F1;&#x56FE;&#x4E0A;&#xFF0C;&#x4E00;&#x4E2A;&#x6307;&#x6807;&#x7ED8;&#x5236;&#x4E86;&#x6574;&#x4E2A;&#x4E00;&#x5929;&#x7684;&#x9AD8;&#x4EF7;&#x3002;&#x8FD9;&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#x5BF9;&#x5206;&#x6790;&#x662F;&#x6709;&#x7528;&#x7684;&#xFF0C;&#x4F46;&#x5BF9;&#x56DE;&#x6D4B;&#x7B56;&#x7565;&#x4E0D;&#x8D77;&#x4F5C;&#x7528;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x5BF9;&#x6B64;&#x8FDB;&#x884C;&#x4E86;&#x7814;&#x7A76;&#xFF0C;&#x5E76;&#x5728; Pine &#x7248;&#x672C; 3 &#x4E2D;&#x8FDB;&#x884C;&#x4E86;&#x4FEE;&#x6539;&#x3002;&#x5982;&#x679C;&#x7528; //@version=3 &#x6307;&#x4EE4;&#x7F16;&#x8BD1;&#x8FD9;&#x4E2A;&#x6307;&#x6807;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5B8C;&#x5168;&#x4E0D;&#x540C;&#x7684;&#x753B;&#x9762;&#x3002;</p>
<p><img src="../img/8a/V3.png" alt="&#x793A;&#x4F8B;&#x56FE;"></p>
<p>&#x4F46;&#x65E7;&#x7684;&#x884C;&#x4E3A;&#x4ECD;&#x7136;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x3002;&#x6211;&#x4EEC;&#x7ED9; security &#x51FD;&#x6570;&#xFF08;&#x7B2C;&#x4E94;&#x4E2A;&#xFF09;&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x53EB;&#x505A; lookahead&#x3002;</p>
<p>&#x5B83;&#x53EF;&#x4EE5;&#x91C7;&#x53D6;&#x4E24;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x503C;&#x7684;&#x5F62;&#x5F0F;&#xFF1A;barmerge.lookahead_off&#xFF08;&#x800C;&#x8FD9;&#x662F; Pine &#x7B2C;&#x4E09;&#x7248;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF09;&#x6216; barmerge.lookahead_on&#xFF08;&#x8FD9;&#x662F; Pine &#x7B2C;&#x4E8C;&#x7248;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF09;&#x3002;</p>
<h2 id="&#x5220;&#x9664;&#x4E86;&#x81EA;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;">&#x5220;&#x9664;&#x4E86;&#x81EA;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;</h2>
<p>Pine &#x7248;&#x672C; 2 &#x7684;&#x4EE3;&#x7801;&#x6BB5;&#xFF0C;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x81EA;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#xFF1A;</p>
<pre><code>//@version=2
//...
s = nz(s[1]) + close
</code></pre><p>&#x7528; Pine &#x7248;&#x672C; 3 &#x7F16;&#x8BD1;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x4F1A;&#x7ED9;&#x4F60;&#x4E00;&#x4E2A; Undeclared identifier &apos;s&apos; &#x9519;&#x8BEF;&#x3002;&#x5E94;&#x8BE5;&#x6539;&#x5199;&#x4E3A;&#xFF1A;</p>
<pre><code>//@version=3
//...
s = 0.0
s := nz(s[1]) + close
</code></pre><p>s &#x73B0;&#x5728;&#x662F;&#x4E00;&#x4E2A;&#x53EF;&#x53D8;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5728;&#x7B2C; 3 &#x884C;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x3002;&#x5728;&#x7B2C; 3 &#x884C;&#xFF0C;&#x521D;&#x59CB;&#x503C;&#x5411; Pine &#x7F16;&#x8BD1;&#x5668;&#x63D0;&#x4F9B;&#x4E86;&#x5173;&#x4E8E;&#x53D8;&#x91CF;&#x7C7B;&#x578B;&#x7684;&#x4FE1;&#x606F;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A; float&#x3002;</p>
<p>&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7528;&#x4E00;&#x4E2A; na &#x503C;&#x6765;&#x521D;&#x59CB;&#x5316;&#x8FD9;&#x4E2A;&#x53EF;&#x53D8;&#x7684;&#x53D8;&#x91CF;&#xFF08;&#x6BD4;&#x5982; s&#xFF09;&#x3002;&#x4F46;&#x5728;&#x590D;&#x6742;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD9;&#x5C31;&#x884C;&#x4E0D;&#x901A;&#x4E86;&#x3002;</p>
<h2 id="&#x5220;&#x9664;&#x4E86;&#x6B63;&#x5411;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;">&#x5220;&#x9664;&#x4E86;&#x6B63;&#x5411;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;</h2>
<pre><code>//@version=2
//...
d = nz(f[1])
e = d + 1
f = e + close
</code></pre><p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;f &#x662F;&#x4E00;&#x4E2A;&#x6B63;&#x5411;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5728;&#x7B2C; 3 &#x884C;&#x88AB;&#x5F15;&#x7528;&#xFF0C;&#x7136;&#x540E;&#x624D;&#x88AB;&#x58F0;&#x660E;&#x548C;&#x521D;&#x59CB;&#x5316;&#x3002;&#x5728; Pine &#x7684;&#x7B2C; 3 &#x7248;&#x4E2D;&#xFF0C;&#x8FD9;&#x5C06;&#x7ED9;&#x4F60;&#x4E00;&#x4E2A;&#x9519;&#x8BEF; Undeclared identifier &apos;f&apos;&#x3002;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x5728; Pine &#x7248;&#x672C; 3 &#x4E2D;&#x5E94;&#x8BE5;&#x6539;&#x5199;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>//@version=3
//...
f = 0.0
d = nz(f[1])
e = d + 1
f := e + close
</code></pre><h2 id="&#x89E3;&#x51B3;-security-&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x53EF;&#x53D8;&#x53D8;&#x91CF;&#x7684;&#x95EE;&#x9898;">&#x89E3;&#x51B3; security &#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x53EF;&#x53D8;&#x53D8;&#x91CF;&#x7684;&#x95EE;&#x9898;</h2>
<p>&#x5F53;&#x4F60;&#x5C06;&#x811A;&#x672C;&#x8FC1;&#x79FB;&#x5230;&#x7B2C; 3 &#x7248;&#x65F6;&#xFF0C;&#x6709;&#x53EF;&#x80FD;&#x5728;&#x5220;&#x9664;&#x81EA;&#x5F15;&#x7528;&#x548C;&#x524D;&#x5411;&#x5F15;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x540E;&#xFF0C;Pine &#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x7ED9;&#x4F60;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#xFF1A;</p>
<pre><code>//@version=3
//...
s = 0.0
s := nz(s[1]) + close
t = security(tickerid, period, s)
</code></pre><p>Cannot use mutable variable as an argument for security function!</p>
<p>&#x8FD9;&#x4E2A;&#x9650;&#x5236;&#x5B58;&#x5728;&#x4E8E; Pine &#x4E2D;&#x5F15;&#x5165;&#x7684;&#x53EF;&#x53D8;&#x53D8;&#x91CF;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x7B2C;&#x4E8C;&#x7248;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x50CF;&#x4EE5;&#x524D;&#x90A3;&#x6837;&#x89E3;&#x51B3;&#xFF1A;&#x7528;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x53EF;&#x53D8;&#x91CF;&#x6765;&#x5305;&#x88F9;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code>//@version=3
//...
calcS() =&gt;
    s = 0.0
    s := nz(s[1]) + close
t = security(tickerid, period, calcS())
</code></pre><h2 id="&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x7684;&#x6570;&#x5B66;&#x64CD;&#x4F5C;">&#x7981;&#x6B62;&#x4F7F;&#x7528;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x7684;&#x6570;&#x5B66;&#x64CD;&#x4F5C;</h2>
<p>&#x5728; Pine Script v2 &#x4E2D;&#xFF0C;&#x6709;&#x5C06;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x5B57;&#x7C7B;&#x578B;&#x7684;&#x89C4;&#x5219;&#x3002;&#x5728; V3 &#x4E2D;&#x8FD9;&#x662F;&#x88AB;&#x7981;&#x6B62;&#x7684;&#x3002;&#x6570;&#x5B57;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x8F6C;&#x6362;&#x4E3A;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#xFF08;0 &#x548C; na &#x503C;&#x4E3A;&#x5047;&#xFF0C;&#x5176;&#x4ED6;&#x6570;&#x5B57;&#x4E3A;&#x771F;&#xFF09;&#x3002;&#x4F8B;&#x5B50;&#xFF08;&#x5728; v2 &#x4E2D;&#xFF0C;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x7F16;&#x8BD1;&#x826F;&#x597D;&#xFF09;&#xFF1A;</p>
<pre><code>//@version=2
study(&quot;My Script&quot;)
s = close &gt;= open
s1 = close[1] &gt;= open[1]
s2 = close[2] &gt;= open[2]
sum = s + s1 + s2
col = sum == 1 ? white : sum == 2 ? blue : sum == 3 ? red : na
bgcolor(col)
</code></pre><p>&#x53D8;&#x91CF; s&#x3001;s1 &#x548C; s2 &#x662F; bool &#x7C7B;&#x578B;&#x7684;&#x3002;&#x4F46;&#x5728;&#x7B2C; 6 &#x884C;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B83;&#x4EEC;&#x4E2D;&#x7684;&#x4E09;&#x4E2A;&#x76F8;&#x52A0;&#xFF0C;&#x5E76;&#x5C06;&#x7ED3;&#x679C;&#x5B58;&#x50A8;&#x5728;&#x4E00;&#x4E2A;&#x53D8;&#x91CF; sum &#x4E2D;&#x3002;sum &#x662F;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x4E0D;&#x80FD;&#x5C06;&#x5E03;&#x5C14;&#x503C;&#x76F8;&#x52A0;&#x3002;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x88AB;&#x9690;&#x542B;&#x5730;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x5B57;&#xFF08;&#x771F;&#x503C;&#x4E3A; 1.0&#xFF0C;&#x5047;&#x503C;&#x4E3A; 0.0&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x5B83;&#x4EEC;&#x76F8;&#x52A0;&#x3002;</p>
<p>&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x4F1A;&#x5BFC;&#x81F4;&#x5728;&#x66F4;&#x590D;&#x6742;&#x7684;&#x811A;&#x672C;&#x4E2D;&#x51FA;&#x73B0;&#x65E0;&#x610F;&#x7684;&#x9519;&#x8BEF;&#x3002;&#x8FD9;&#x5C31;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x6211;&#x4EEC;&#x4E0D;&#x518D;&#x5141;&#x8BB8;&#x5C06;&#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x9690;&#x5F0F;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x5B57;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F60;&#x8BD5;&#x56FE;&#x5C06;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x7F16;&#x8BD1;&#x4E3A; Pine v3 &#x4EE3;&#x7801;&#xFF0C;&#x4F60;&#x4F1A;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;Cannot call \ <code>operator +</code> with arguments (series<strong>bool, series</strong>bool); &lt;...&gt;  &#x8FD9;&#x610F;&#x5473;&#x7740;&#x4F60;&#x4E0D;&#x80FD;&#x5BF9;&#x5E03;&#x5C14;&#x503C;&#x4F7F;&#x7528;&#x52A0;&#x6CD5;&#x8FD0;&#x7B97;&#x3002;&#x4E3A;&#x4E86;&#x4F7F;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x5728; Pine v3 &#x4E2D;&#x5DE5;&#x4F5C;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x505A;&#x4EE5;&#x4E0B;&#x4FEE;&#x6539;:</p>
<pre><code>//@version=3
study(&quot;My Script&quot;)
bton(b) =&gt;
    b ? 1 : 0
s = close &gt;= open
s1 = close[1] &gt;= open[1]
s2 = close[2] &gt;= open[2]
sum = bton(s) + bton(s1) + bton(s2)
col = sum == 1 ? white : sum == 2 ? blue : sum == 3 ? red : na
bgcolor(col)
</code></pre><p>&#x5982;&#x679C;&#x4F60;&#x771F;&#x7684;&#x9700;&#x8981;&#xFF0C;&#x51FD;&#x6570; bton&#xFF08;boolean-to-number &#x7684;&#x7F29;&#x5199;&#xFF09;&#x53EF;&#x4EE5;&#x660E;&#x786E;&#x5730;&#x5C06;&#x4EFB;&#x4F55;&#x5E03;&#x5C14;&#x503C;&#x8F6C;&#x6362;&#x4E3A;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 附录">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2how.html" class="navigation navigation-next " aria-label="Next page: 操作指南">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Pine 第 3 版迁移指南","level":"1.10.1","depth":2,"next":{"title":"操作指南","level":"1.10.2","depth":2,"path":"appendix/2how.md","ref":"./appendix/2how.md","articles":[]},"previous":{"title":"附录","level":"1.10","depth":1,"path":"appendix/index.md","ref":"./appendix/index.md","articles":[{"title":"Pine 第 3 版迁移指南","level":"1.10.1","depth":2,"path":"appendix/1migration.md","ref":"./appendix/1migration.md","articles":[]},{"title":"操作指南","level":"1.10.2","depth":2,"path":"appendix/2how.md","ref":"./appendix/2how.md","articles":[]},{"title":"Pine 的编译和执行错误","level":"1.10.3","depth":2,"path":"appendix/3err.md","ref":"./appendix/3err.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"剑客","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Pine Script 用户手册中文版","language":"zh","gitbook":"*","description":"Pine Script 文档中文翻译"},"file":{"path":"appendix/1migration.md","mtime":"2021-06-14T06:37:50.629Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-06-14T07:42:18.199Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

